package com.quantgroup.data.saastest.config;

import org.springframework.util.StringUtils;

/**
 * @author yangjinhua
 */
public class DataSourceUtil {
    private static final String JDBC_URL_ARGS = "useUnicode=true&characterEncoding=UTF-8&useOldAliasMetadataBehavior=true&zeroDateTimeBehavior=convertToNull";

    /**
     * 拼接完整的JDBC URL
     */
    public static String getJDBCUrl(String baseUrl) {
        if (!StringUtils.hasText(baseUrl)) {
            return null;
        }
        if (baseUrl.contains("?")) {
            if (baseUrl.lastIndexOf("&") != baseUrl.length()-1) {
                baseUrl = baseUrl + "&";
            }
        } else {
            baseUrl = baseUrl + "?";
        }
        return baseUrl + JDBC_URL_ARGS;
    }

}